<template>
  <div>

    <el-form :inline="true" :model="search" class="user-search">
      <el-form-item label="搜索">
        <el-input size="small" v-model="search.carId" placeholder="车牌号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input size="small" v-model="search.location" placeholder="车位编号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input size="small" v-model="search.price" placeholder="付款价格"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="sel()">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-divider></el-divider>
    <el-table
        :data="tableData"
        style="width: 100%"
        :default-sort="{prop: 'date', order: 'descending'}"
    >

      <el-table-column prop="location" label="车位编号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="carId" label="车牌号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="inTime" sortable label="入场时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="outTime" sortable label="出场时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="stopTime" sortable label="停车时间（小时）" header-align="center" align="center"></el-table-column>
      <el-table-column prop="price" sortable label="停车费用" header-align="center" align="center"></el-table-column>
    </el-table>


  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
      search: {},
    };
  },
  methods: {

    sel(){
      let url = 'http://localhost:8080/user/search'
      this.search.cardId = localStorage.getItem('cardId')
      this.axios.post(url,this.search).then((response)=>{
        let responseBody =response.data
        if (responseBody.code==200){
          this.tableData=responseBody.data;
        }else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });
    },

    //请求车位列表
    loadParkingSpaceList() {
      let cardId = localStorage.getItem('cardId')
      let url = 'http://localhost:8080/user/getHistory?cardId=' + cardId;
      this.axios.get(url).then((response) => {
        let responseBody = response.data;
        console.log(this.editForm)
        if (responseBody.code == 200) {
          this.tableData = responseBody.data;
          console.log(this.tableData)
        } else {
          this.$message({
            showClose: true,
            message: responseBody.message,
            type: 'error'
          });
        }
      });

    }
  }
  ,
  created() {
    this.loadParkingSpaceList()
  }
}
</script>
